#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
const int N = 1e5 + 5;
const int W = 4e4 + 5;

int n, c;
struct Node {
  int v, w;
} a[N];
int tot;
int dp[W];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> c;
  rep(i, 1, n) {
    int v, w, m;
    cin >> v >> w >> m;
    for (int j = 1; j <= m; j <<= 1) {
      a[++tot] = Node{v * j, w * j};
      m -= j;
    }
    if (m) a[++tot] = Node{v * m, w * m};
  }
  rep(i, 1, tot) {
    per(j, c, a[i].w) { dp[j] = max(dp[j], dp[j - a[i].w] + a[i].v); }
  }
  cout << dp[c];
  return 0;
}